package com.itcast.test.serveice;

import com.itcast.test.bean.User;
import com.itcast.test.dao.AddStu;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add")
public class AddStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        User u = new User(Integer.parseInt(id),username,Integer.parseInt(age));
        AddStu s = new AddStu();
        s.addStu(u);
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write("添加成功");
        resp.setHeader("refresh","1;URL=index.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
